/*
 * @(#)xin.tianhui.cloud.weblog.manager.impl
 * @(#)ArticleMngImpl.java	2018-04-07
 * 
 * Copyright © 2018-2027, All rights reserved.
 * homeanter
 */
package xin.tianhui.cloud.weblog.manager.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import xin.tianhui.cloud.weblog.core.model.dto.PagingDTO;
import xin.tianhui.cloud.weblog.core.model.vo.PagingVO;
import xin.tianhui.cloud.weblog.manager.IArticleMng;
import xin.tianhui.cloud.weblog.model.dto.ArticleResultDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleTypeResultDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleAlterDTO;
import xin.tianhui.cloud.weblog.model.dto.ArticleQueryDTO;
import xin.tianhui.cloud.weblog.service.IArticleService;
import xin.tianhui.cloud.weblog.service.IArticleTypeService;

/**
 * <P>Description: TODO</P>
 * @ClassName: ArticleMngImpl
 * @author junchen homeanter@163.com  
 * @date 2018-04-07 15:05:00
 * @see TODO
 */
@Component
public class ArticleMngImpl implements IArticleMng{
	
	@Autowired
	private IArticleService articleService;
	
	@Autowired
	private IArticleTypeService articleTypeService;
	
	@Override
	public ArticleResultDTO getArticle(Integer bid) {
		return articleService.getArticleById(bid);
	}
	@Override
	public PagingVO<ArticleResultDTO> articlePaging(PagingDTO paging,ArticleQueryDTO queryDto) {
		if(queryDto==null) {
			queryDto = new ArticleQueryDTO();
		}
		return articleService.getArticlePage(paging,queryDto);
	}
	
	@Override
	public List<ArticleTypeResultDTO> articleType() {
		return articleTypeService.articleType();
	}
	@Override
	public ArticleResultDTO alterArticle(ArticleAlterDTO article) {
		if(article!=null) {
			if(article.getBid() == null || article.getBid()==0) {
				article.setBid(null);
				return articleService.insertArticle(article);
			}else {
				return articleService.updateArticle(article);
			}
		}
		return null;
	}
	
}
